package com.ruoyi.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.api.domain.UserAddress;
import com.ruoyi.api.mapper.UserAddressMapper;
import com.ruoyi.api.service.IUserAddressService;
import com.ruoyi.api.vo.UserAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 寻觅
 * @since 2025-05-28
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements IUserAddressService {
    @Autowired
    UserAddressMapper userAddressMapper;

    @Override
    public List<UserAddressVo> info(Long userId) {
        List<UserAddressVo> info = userAddressMapper.info(userId);
        info.forEach(userAddressVo -> {
            userAddressVo.setAddress(userAddressVo.getLevelOneName() +
                    " " + userAddressVo.getLevelTwoName() +
                    " " + userAddressVo.getLevelThreeName() +
                    " " + userAddressVo.getLevelFourName() +
                    " " + userAddressVo.getAddress());
        });
        return info;
    }

    @Override
    public Integer edit(UserAddress userAddress) {
        userAddressMapper.deleteById(userAddress.getId());
        return userAddressMapper.insert(userAddress);
    }
}
